package it.diego.projecttwo;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.ScaleAnimation;
import android.widget.AbsoluteLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.AbsoluteLayout.LayoutParams;

public class DragAndDropDueActivity extends Activity {

	ImageView img = null;
	AbsoluteLayout aLayout;
	int status = 0;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.drag_and_drop_due);
		
		aLayout = (AbsoluteLayout) findViewById(R.id.absLayout);

		img = (ImageView) findViewById(R.id.imageView);

		// sa.setFillAfter(true);

		img.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {

				status = 1;
				Log.i("ImageStatus", "" + status);
				// img.setBackgroundColor(Color.WHITE);

				return false;
			}
		});
		aLayout.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				// TODO Auto-generated method stub
				Log.i("touch", "" + event);

				if (status == 1) // any event from down and move
				{
					LayoutParams lp = new LayoutParams(
							LayoutParams.WRAP_CONTENT,
							LayoutParams.WRAP_CONTENT, (int) event.getX()
									- img.getWidth() / 2, (int) event.getY()
									- img.getHeight() / 2);
					img.setLayoutParams(lp);

				}
				if (event.getAction() == MotionEvent.ACTION_UP) {
					status = 0;

					img.setBackgroundColor(Color.TRANSPARENT);

				}
				return true;
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.drag_and_drop_due, menu);
		return true;
	}
}
